<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>

<head>
<title><spring:message code="admin.bonusselectroles.titile" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
	function selectAll(flag , attribute , val){
		var inputs = document.getElementsByTagName("input");

		for(var i=0;i<inputs.length;i++){
 			 if( inputs[i].getAttribute(attribute) == val )
 			   {inputs[i].checked = flag;}
			}
	}

	function filterByRole( roleId ){
  		document.location.href = "bonus_select_roles.htm?roleFilter="+roleId;
	}

	function selectItems(){
		var roles = [];
		var users = [];
		
		var inputs = document.getElementsByTagName("input");

		for(var i=0;i<inputs.length;i++){
			 var cbx = inputs[i];
			 if( cbx.name == 'roleId' && cbx.checked )
			   { 
				 roles[roles.length] = {
						                  "id":cbx.value,
						                  "name":cbx.getAttribute('roleName')
						 			   };
			   }

			 if( cbx.name == 'userId' && cbx.checked )
			   { 
				 users[users.length] = {
						                  "id":cbx.value,
						                  "email":cbx.getAttribute('email')
						 			   };
			   }
			   
			}

		window.opener.setRolesAndUsers( roles , users);
		window.close();
		
	}
	</script>
</head>

<body> 
<form id="f1">

<table border=0 cellpadding=0 cellspacing=0 width=100%>
	<tr>
		<td colspan="2" align="center">
		<h3><spring:message code="admin.bonusselectroles.label.selectrolesusers" /></h3>
		</td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>


	<tr>
		<td colspan="2">
		<table border="1" width=90%>
			<tr>
				<th colspan="3"><spring:message code="admin.bonusselectroles.label.roles" /></th>
			</tr>
			<tr>
				<td align="center"><input type="checkbox"
					onclick="selectAll(this.checked,'className','Role')"></td>
				<td><spring:message code="admin.bonusselectroles.label.roleid" /></td>
				<td><spring:message code="admin.bonusselectroles.label.name" /></td>
			</tr>

			<c:forEach var="r" items="${roleList}">
				<tr class="tr_record">
					<td align="center"><input type="checkbox" className="Role"
						name="roleId" value="${r.id}" roleName="${r.name}"></td>
					<td>${r.id}</td>
					<td>${r.name}</td>
				</tr>
			</c:forEach>


			<tr>
				<td colspan="3"><input type="button" class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.bonusselectroles.button.ok" />"
					onclick="selectItems();"> <input type="button" class='ui-button ui-state-default ui-corner-all'
					value="<spring:message code="admin.bonusselectroles.button.close" />" onclick="window.close();"></td>
			</tr>
		</table>

		<table border="1" width=90%>
			<tr>
				<th colspan="6"><spring:message code="admin.bonusselectroles.label.users" /> &nbsp; <select name="roleFilter">
					<option value="" selected>Select All Roles</option>

					<c:forEach items="${roleList}" var="item">
						<option value="${item.id}">${item.name}</option>
					</c:forEach>

				</select> <input type="button" class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.bonusselectroles.button.listusers" />"
					onclick="filterByRole(this.form.roleFilter[this.form.roleFilter.selectedIndex].value)">
				</th>

			</tr>

			<tr>
				<td align="center"><input type="checkbox"
					onclick="selectAll(this.checked,'className','User')" /></td>
				<td><spring:message code="admin.bonusselectroles.label.userid" /></td>
				<td><spring:message code="admin.bonusselectroles.label.email" /></td>
				<td><spring:message code="admin.bonusselectroles.label.role" /></td>
				<td><spring:message code="admin.bonusselectroles.label.firstname" /></td>
				<td><spring:message code="admin.bonusselectroles.label.lastname" /></td>
			</tr>


			<c:forEach var="r" items="${listUsers.pageItems}" varStatus="i">
				<tr class="tr_record" class="UserTr" role="${r.role.id}">
					<td align="center"><input type="checkbox" class="User"
						name="userId" value="${r.id}" email="${r.email}"></td>
					<td>${r.id}</td>
					<td>${r.email}</td>
					<td>${r.role.name}</td>
					<td>${r.firstName}</td>
					<td>${r.lastName}</td>
				</tr>
			</c:forEach>

			<tr>
				<td colspan="6"><input type="button" class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.bonusselectroles.button.ok" />"
					onclick="selectItems();"> <input type="button" class='ui-button ui-state-default ui-corner-all'
					value="<spring:message code="admin.bonusselectroles.button.close" />" onclick="window.close();"></td>
			</tr>
		</table>

		</td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>


</table>
</form>
<%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>